package com.zdy.im.user.dao;


import java.util.Collection;
import java.util.Map;

import com.sixeco.framework.core.db.ext.Query;
import com.sixeco.framework.core.mybatis.MyBatisBaseCacheDao;
import com.sixeco.framework.util.PageUtils;
import com.zdy.im.user.entity.ImRoomInfo;
import com.zdy.im.user.mapper.ImRoomInfoMapper;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;




@Service("imRoomInfoDao")
public class ImRoomInfoDao extends MyBatisBaseCacheDao<ImRoomInfoMapper, ImRoomInfo> {

    @Autowired
    private ImRoomInfoMapper  imRoomInfoMapper;

    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ImRoomInfo>  iPage =  new Query<ImRoomInfo>().getPage(params);

        QueryWrapper<ImRoomInfo> query =  new QueryWrapper<>();

        IPage<ImRoomInfo> page = this.page(iPage,query );

        return new PageUtils(page);
    }


    @Override
    public void saveData(List<Object> list) {
        List<ImRoomInfo> datas = new ArrayList<>();
        list.forEach(e -> datas.add(ImRoomInfo.build().clone(e)));
        this.saveBatch(datas, BATCH_SIZE);
        }

    /**
     * 查询ids，所有添加的群
     * @param ids
     * @return
     */
    public List<ImRoomInfo> selectListByIds(Collection<Long> ids){
        QueryWrapper<ImRoomInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status",1)
                .in("id", ids)
                .orderByDesc("create_date");
        return this.list(queryWrapper);
    }
}